<?php

/**
 * This is the model class for table "{{_model2serv}}".
 *
 * The followings are the available columns in table '{{_model2serv}}':
 * @property string $linkId
 * @property string $modelId
 * @property string $serviceId
 * @property string $blockNo
 * @property integer $sort
 */
class Model2servForm extends CFormModel {

	public $modelId;
	public $linkId;
	//public $modelId;
	public $serviceId;
	public $blockNo;
	public $sort;
	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules() {
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('modelId', 'required'),
			array('modelId', 'unique', 'on' => 'create'),
			array('sort', 'numerical', 'integerOnly' => true),
			array('modelId, serviceId, blockNo', 'length', 'max' => 10),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('linkId, modelId, serviceId, blockNo, sort', 'safe', 'on' => 'search'),
		);
	}


	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels() {
		return array(
			'linkId' => 'Link',
			'modelId' => 'Model',
			'serviceId' => 'Service',
			'blockNo' => 'Block No',
			'sort' => 'Sort',
		);
	}

	public function getModels() {	
		$query = "SELECT * FROM {{tree}} WHERE pageType = 'model'";
		$models = Yii::app()->db->createCommand($query)->queryAll(true);
		foreach ($models as $model) {
			$array[$model['pageId']] = $model['pageTitle'];
		}
		return $array;
	}	

}
